package com.neuedu.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neuedu.entity.Level;
import com.neuedu.mapper.LevelMapper;
import com.neuedu.service.LevelService;
import com.neuedu.vo.LevelCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class LevelServiceImpl extends ServiceImpl<LevelMapper, Level> implements LevelService {

    @Override
    public Page<Level> getLevelList(LevelCondition levelCondition) {

        Page page = new Page(levelCondition.getCurrentPage(), levelCondition.getPageSize());

        return this.query().like("level_name", levelCondition.getLevelName()).page(page);
    }

    @Autowired
    private LevelMapper levelMapper;

    @Override
    public boolean removeEnable(int levelId) {
        return levelMapper.findDoctorCount(levelId)==0;
    }

    @Override
    public boolean deleteBatch(String levelIds) {

        //将字符串拆分成数组  "1,2,3" --> [1,2,3]
        String[] arr = levelIds.split(",");

        //字符串数组转换集合  [1,2,3] --> {1,2,3}
        List<Integer> list = new ArrayList<>();

        for (String s : arr) {
            list.add(Integer.parseInt(s));
        }

        return this.removeByIds(list);
    }


}
